# 名称:Backdream
# 时间2022/12/26  21:02
#搜索页面类

from appium.webdriver.common.mobileby import MobileBy as By
from pages.base_page import BasePage


class SearchPage(BasePage):
    '''搜索页面定位器'''
    # 早餐鸡蛋饼定位器
    search_breakfast_egg_locator = (By.XPATH, "//android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.FrameLayout[1]/android.widget.LinearLayout[1]/android.widget.LinearLayout[1]/android.support.v4.view.ViewPager[1]/android.widget.LinearLayout[1]/android.view.ViewGroup[1]/android.support.v7.widget.RecyclerView[1]/android.widget.LinearLayout[3]/android.widget.TextView[1]")

    # 获取鸡蛋饼早餐文本
    def search_breakfast_egg(self):
        return self.driver.find_element(*self.search_breakfast_egg_locator).text

    # 搜索热门标签
    search_label_locator = (By.XPATH, "//android.widget.TextView[@resource-id=\"com.gfeng.daydaycook:id/historyTv\" and @text=\"早餐\"]")

    def search_label_click(self):
        self.driver.find_element(*self.search_label_locator).click()

    #点击土豆
    potato_btn_locator=(By.XPATH,"//android.view.ViewGroup[@resource-id=\"com.gfeng.daydaycook:id/hotFlow\"]/android.widget.FrameLayout[12]/android.widget.TextView[1]")
    def patato_btn_click(self):
        self.driver.find_element(*self.potato_btn_locator).click()

    #食谱 元素父目录定位
    food_father_locator=(By.XPATH,"//android.support.v7.widget.RecyclerView[@resource-id=\"com.gfeng.daydaycook:id/recyclerView\"]")
    def food_father(self):
        return self.driver.find_element(*self.food_father_locator)

    #第一层定位
    food_1floor=(By.CLASS_NAME,"android.widget.LinearLayout")
    #第二层定位
    food_2floor=(By.CLASS_NAME,"android.widget.TextView")

